import UserSession from "@/UserSession"
import { Modal,Button,Upload } from "antd"

const ImportModal = props => {
  const cancelImportModal = () => {
    if(props.handleCancel){
      props.handleCancel()
    }
  }
  const downloadTemplate = () => {
    if(props.handleDownload){
      props.handleDownload()
    }
  }

  const handleUpFile = (info) => {
    if(props.handleUpload){
      props.handleUpload(info)
    }
  }

  const importProps = {
    accept: ".xlsx,.xls",
    onChange: handleUpFile,
    showUploadList:false,
    action:props.importUrl,
    headers:{
      'Authorization':`Bearer ${UserSession.getToken()}`
    }
  };

  return (
    <Modal
      {...props.attributeList}
      onCancel={cancelImportModal}
      footer={[
        <Button onClick={cancelImportModal}>取消</Button>,
        <Upload {...importProps}>
          <Button style={{marginLeft:10}} type="primary" loading={props.importLoading ? props.importLoading : false}>开始导入</Button>
        </Upload>
      ]}
      maskStyle={{zIndex:"1004"}}
      zIndex={1005}
    >
        <p>请按照模板中的示例格式进行编辑上传：<Button type="link" onClick={downloadTemplate}>下载模板</Button></p>
        <p>上传文件格式需要为“.xlsx”或“.xls”类型的Excel文件</p>
    </Modal>
  )
}

export default ImportModal